#include "ProviderPseudostate.h"

#include "core/AppSignals.h"

ProviderPseudostate::ProviderPseudostate()
    : PropertyProvider()
{
}

void ProviderPseudostate::initEditor(
    QtTreePropertyBrowser* editor,
    shared_ptr<BaseElement> entity
)
{
    entity_ = dynamic_pointer_cast<uml::Pseudostate>(entity);
    propertyToId.clear();
    PropertyProvider::initEditor(editor, entity);

    QStringList kindNames;
    kindNames.append("initial");
    kindNames.append("deepHistory");
    kindNames.append("shallowHistory");
    kindNames.append("join");
    kindNames.append("fork");
    kindNames.append("junction");
    kindNames.append("choice");
    kindNames.append("entryPoint");
    kindNames.append("exitPoint");
    kindNames.append("terminate");
    addProperty("kind", "kind", static_cast<int>(entity_->kind()), kindNames);
    addProperty("name", "name", entity_->name());
    addProperty("qualifiedName", "qualifiedName", entity_->qualifiedName());
    QStringList visibilityNames;
    visibilityNames.append("public");
    visibilityNames.append("private");
    visibilityNames.append("protected");
    visibilityNames.append("package");
    addProperty("visibility", "visibility", static_cast<int>(entity_->visibility()), visibilityNames);

}

void ProviderPseudostate::valueChanged(QtProperty* property, bool value)
{
    QString id = propertyToId[property];
    
}

void ProviderPseudostate::valueChanged(QtProperty* property, double value)
{
    QString id = propertyToId[property];
    
}

void ProviderPseudostate::valueChanged(QtProperty* property, int value)
{
    QString id = propertyToId[property];
    if (id == "kind") {
        entity_->setKind(static_cast<PseudostateKind>(value));
        emit appSignals->onElementChanged(this, entity_);
    } else if (id == "visibility") {
        entity_->setVisibility(static_cast<VisibilityKind>(value));
        emit appSignals->onElementChanged(this, entity_);
    }
}

void ProviderPseudostate::valueChanged(QtProperty* property, QString value)
{
    QString id = propertyToId[property];
    if (id == "name") {
        entity_->setName(value);
        emit appSignals->onElementRenamed(this, entity_);
    } else if (id == "qualifiedName") {
        entity_->setQualifiedName(value);
        emit appSignals->onElementChanged(this, entity_);
    }
}
